#!/bin/bash

# 获取脚本所在目录的绝对路径
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
WORKSPACE="$SCRIPT_DIR/.."
cd "$WORKSPACE"

echo "当前工作目录: $(pwd)"

LUBAN_DLL="/Users/jiumao/Documents/UGit/luban_examples/Tools/Luban/Luban.dll"
CONF_ROOT="./_excel"
#POSTPROCESS="./addons/luban_godot/LubanTool/post_process.py"
GEN_DIR="./data"

# 确保必要的目录存在
mkdir -p "$GEN_DIR/_raw_gen"
mkdir -p "$GEN_DIR/json"
mkdir -p "$GEN_DIR/gen"
mkdir -p "$CONF_ROOT"

# 运行 Luban
dotnet "$LUBAN_DLL" \
    -t all \
    -c gdscript-split-json \
    -d json \
    --conf "$CONF_ROOT/luban.conf" \
    -x outputCodeDir="$GEN_DIR/_raw_gen" \
    -x outputDataDir="$GEN_DIR/json" \
    -x tableImporter.name=hydrcat \
    -x pathValidator.rootDir="."

# # 检查 dotnet 命令是否成功执行
# if [ $? -eq 0 ]; then
#     echo "Luban 生成成功"
    
#     # 检查 schema.gd 文件是否存在
#     if [ -f "$GEN_DIR/_raw_gen/schema.gd" ]; then
#         python "$POSTPROCESS" "$GEN_DIR/_raw_gen/schema.gd" "$GEN_DIR/gen"
#         echo "ignore this" > "$GEN_DIR/_raw_gen/.gdignore"
#         echo "后处理完成"
#     else
#         echo "错误: 找不到 schema.gd 文件: $GEN_DIR/_raw_gen/schema.gd"
#         ls -la "$GEN_DIR/_raw_gen/"
#     fi
# else
#     echo "错误: Luban 生成失败"
# fi